package com.yc.login;

import com.yc.login.bean.LoginProperties;
import com.yc.login.web.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration
@ComponentScan("com.yc.login")
@ConditionalOnProperty(prefix = "login",name="enable",matchIfMissing = true)
@EnableConfigurationProperties(LoginProperties.class)
public class LoginConfiguration implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;
    @Autowired
    LoginProperties properties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (properties.getLoginScope()!=null&&properties.getLoginScope().length>0) {
            registry.addInterceptor(loginInterceptor)
                    .addPathPatterns(properties.getLoginScope());
        }
    }
}
